#pragma once
#include "BaseDrawable.h"

class Laser : public BaseDrawable
{
protected:
	bool LazerMoving;
	bool bReflect;

public:
	Laser(){};
	Laser(float XPos, float ZPos,int Direction, int Owner)
		:BaseDrawable(D3OBJ_LASER, D3DXVECTOR3(XPos,2,ZPos))
	{
		SetOwner(Owner);
		InitialRotate(Direction);
	};

	void Update()
	{
		if(LazerMoving == true)
		{
			switch(meiDirIndex)

			{
			case DIR_NORTH:	if(Timer::Into()->Wait(0.1)){mvPosition.z++;bReflect = true;}	break;
			case DIR_EAST:	if(Timer::Into()->Wait(0.1)){mvPosition.x++;bReflect = true;}	break;
			case DIR_SOUTH:	if(Timer::Into()->Wait(0.1)){mvPosition.z--;bReflect = true;}	break;
			case DIR_WEST:	if(Timer::Into()->Wait(0.1)){mvPosition.x--;bReflect = true;}	break;
			}
		}
	}

	bool Reflect(int Obj, int ObjDir)
	{
		if(bReflect == true)
		{
		//Returns true if the game ends
		switch(Obj)
		{
		case D3OBJ_EMPTY:	break;
		case D3OBJ_PYRAMID:	switch(ObjDir)
							{
								case DIR_NORTH:	switch(meiDirIndex)
												{
													case DIR_NORTH:	LazerMoving = false;		break;
													case DIR_EAST:	LazerMoving = false;		break;
													case DIR_SOUTH:	meiDirIndex = DIR_EAST;		break;
													case DIR_WEST:	meiDirIndex = DIR_NORTH;	break;
												}
												break;
								case DIR_EAST:	switch(meiDirIndex)
												{
													case DIR_NORTH:	meiDirIndex = DIR_EAST;		break;
													case DIR_EAST:	LazerMoving = false;		break;
													case DIR_SOUTH:	LazerMoving = false;		break;
													case DIR_WEST:	meiDirIndex = DIR_SOUTH;	break;
												}
												break;
								case DIR_SOUTH:	switch(meiDirIndex)
												{
													case DIR_NORTH:	meiDirIndex = DIR_WEST;		break;
													case DIR_EAST:	meiDirIndex = DIR_SOUTH;	break;
													case DIR_SOUTH:	LazerMoving = false;		break;
													case DIR_WEST:	LazerMoving = false;		break;
												}
												break;
								case DIR_WEST:	switch(meiDirIndex)
												{
													case DIR_NORTH:	LazerMoving = false;		break;
													case DIR_EAST:	meiDirIndex = DIR_NORTH;	break;
													case DIR_SOUTH:	meiDirIndex = DIR_WEST;		break;
													case DIR_WEST:	LazerMoving = false;		break;
												}
												break;
							}
							break;
		case D3OBJ_SCARAB:	switch(ObjDir)
							{
								case DIR_SOUTH:
								case DIR_NORTH:	switch(meiDirIndex)
												{
													case DIR_NORTH:	meiDirIndex = DIR_WEST;		break;
													case DIR_EAST:	meiDirIndex = DIR_SOUTH;	break;
													case DIR_SOUTH:	meiDirIndex = DIR_EAST;		break;
													case DIR_WEST:	meiDirIndex = DIR_NORTH;	break;
												}
												break;
								case DIR_WEST:	
								case DIR_EAST:	switch(meiDirIndex)
												{
													case DIR_NORTH:	meiDirIndex = DIR_EAST;		break;
													case DIR_EAST:	meiDirIndex = DIR_NORTH;	break;
													case DIR_SOUTH:	meiDirIndex = DIR_WEST;		break;
													case DIR_WEST:	meiDirIndex = DIR_SOUTH;	break;
												}
												break;
							}

							break;
		case D3OBJ_SPHINX:	
		case D3OBJ_PHARAOH:	LazerMoving = false; return true;  	 break;
		case D3OBJ_ANUBIS:	LazerMoving = false;
							break;
		case D3OBJ_BOUNDARY:LazerMoving = false;
							Visible = false;
							break;
		}
		}
		bReflect = false;
		
		//Make sure to reset the game state!
		if(!LazerMoving){GameState = ST_PLAY;}
		InitialRotate(meiDirIndex);
		return false;

	};

	void FireLaser(float XPos, float ZPos, int Direction, int Owner)
	{
		meiObjIndex = D3OBJ_LASER;
		mvPosition.x = XPos;
		mvPosition.y = 1.0f;
		mvPosition.z = ZPos;
		InitialRotate(Direction);
		SetOwner(Owner);
		SetVisibility(true);
		LazerMoving = true;
		bReflect = false;
	};
};